import CodeBlock from "@theme/CodeBlock";
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# @farmfe/js-plugin-dts
支持 `.d.ts` 文件。 该插件用于构建的工具库，为您的 ts 代码生成“.d.ts”

## Installation

<Tabs>
  <TabItem value="npm" label="npm">
    <CodeBlock>npm install @farmfe/js-plugin-dts</CodeBlock>
  </TabItem>
  <TabItem value="yarn" label="yarn">
    <CodeBlock>yarn add @farmfe/js-plugin-dts</CodeBlock>
  </TabItem>
  <TabItem value="pnpm" label="pnpm">
    <CodeBlock>pnpm add @farmfe/js-plugin-dts</CodeBlock>
  </TabItem>
</Tabs>

## Usage
```ts {2,6}
import { UserConfig } from '@farmfe/core';
import farmJsPluginDts from '@farmfe/js-plugin-dts';

const config: UserConfig = {
  plugins: [
    farmJsPluginDts({ /* options */ })
  ]
}
```

## Options
```ts
import type { ts, Diagnostic } from 'ts-morph';

export interface DtsPluginOptions {
  /**
   * Depends on the root directory
   */
  root?: string;

  /**
   * Declaration files output directory
   */
  outputDir?: string | string[];

  /**
   * set the root path of the entry files
   */
  entryRoot?: string;

  /**
   * Project init compilerOptions using by ts-morph
   */
  compilerOptions?: ts.CompilerOptions | null;

  /**
   * Project init tsconfig.json file path by ts-morph
   */
  tsConfigPath?: string;

  /**
   * set include glob
   */
  include?: string | string[];

  /**
   * set exclude glob
   */
  exclude?: string | string[];

  /**
   * Whether copy .d.ts source files into outputDir
   *
   * @default false
   */
  copyDtsFiles?: boolean;

  /**
   * Whether emit nothing when has any diagnostic
   *
   * @default false
   */
  noEmitOnError?: boolean;

  /**
   * Whether skip typescript diagnostics
   *
   * @default true
   */
  skipDiagnostics?: boolean;

  /**
   * Customize typescript lib folder path
   *
   * @default undefined
   */
  libFolderPath?: string;

  /**
   * According to the length to judge whether there is any type error
   */
  afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>;
}

```
